package android.medicalcloud.com.yiapp.yilian.utils.android;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.media.RingtoneManager;
import android.medicalcloud.com.yiapp.R;
import android.medicalcloud.com.yiapp.base.utils.Logger;
import android.medicalcloud.com.yiapp.yilian.application.YilianAppcation;
import android.medicalcloud.com.yiapp.yilian.ui.OrderDetailActivity;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;

import java.util.Random;

/**
 * Created by wanggenlin on 17-5-31.
 */
public class PushTool {

    public static void sendNotification(String contentTitle, String contentText, String ticker, String type,String extra) {

//
        Random random = new Random();
        Logger.e("contentTitle"+contentTitle);
        Logger.e("contentText"+contentText);
        Logger.e("ticker"+ticker);
        Logger.e("type"+type);
        Logger.e("extra"+extra);
        Intent intent ;
        PendingIntent pendingIntent = null;
        PendingIntent deletePending = null;
        int notificationID = random.nextInt(10000);
        if (type.equals("ORDER")){
            intent = new Intent(YilianAppcation.instance, OrderDetailActivity.class);
            intent.putExtra("id",extra);
            pendingIntent = PendingIntent.getActivity(YilianAppcation.instance.getApplicationContext(),
                    notificationID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        }


        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(YilianAppcation.instance.getApplicationContext())
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(((BitmapDrawable) YilianAppcation.instance.getResources().getDrawable(R.drawable.ic_launcher)).getBitmap())
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setTicker(ticker)

                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setDeleteIntent(deletePending)
                .setContentIntent(pendingIntent);
        NotificationManager notificationManager =
                (NotificationManager) YilianAppcation.instance.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationID /* ID of notification */,
                notificationBuilder.build());
    }

}
